#include <math.h>
#include <time.h>
#include <string>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <unistd.h>
#include <stddef.h>
#include <string.h>
#include <pthread.h>
#include <semaphore.h>
#include <linux/un.h>
#include <sys/stat.h>
#include <sys/epoll.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#include <linux/spi/spidev.h>

#define SOCK_QEMU_PATH    "@/tmp/mcu_qemu"


int main(int argc, char **argv)
{
	int32_t sockfd = 0;
    socklen_t len = 0;
    struct sockaddr_un address;
	int32_t result = 0;
    char sockname[32];
    memset(sockname, 0, 32);
	
	sprintf(sockname, "%s", SOCK_QEMU_PATH);
    sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
    address.sun_family = AF_UNIX;
    strcpy(address.sun_path, sockname);
    address.sun_path[0] = 0;
    len = strlen(sockname) + offsetof(struct sockaddr_un, sun_path);
	
    result = connect(sockfd, (struct sockaddr *)&address, len);
    if (result == -1) {
        printf("connect failed\n");
        exit(1);
    }
	
	char *data = "hello";
	write(sockfd, data, strlen(data));
	
	close(sockfd);
	return 0;
}

